package com.yoda.mall.admin.controller;

import com.yoda.mall.admin.service.FlashService;
import com.yoda.mall.admin.service.FlashSessionService;
import com.yoda.mall.model.entity.sms.FlashPromotion;
import com.yoda.mall.model.entity.sms.FlashPromotionSession;
import com.yoda.mall.model.vo.FlashPromotionSessionVo;
import com.yoda.mall.model.vo.PageResult;
import com.yoda.mall.model.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/flashSession")
public class FlashSessionController {
    @Autowired
    private FlashSessionService flashSessionService;

    //添加场次
    @PostMapping("create")
    public R createFlashPromotionSession(@RequestBody FlashPromotionSession flashPromotionSession){
        flashSessionService.createFlashPromotionSession(flashPromotionSession);
        return R.success();
    }

    //删除场次
    @PostMapping("delete/{id}")
    public R deleteFlashPromotionSession(@PathVariable Long id){
        flashSessionService.deleteFlashPromotionSession(id);
        return R.success();
    }

    //获取全部场次
    @GetMapping("list")
    public R flashPromotionSessionList(){
        List<FlashPromotionSession> list = flashSessionService.flashPromotionSessionList();
        return R.success(list);
    }

    //通过秒杀活动id获取场次及参与活动的商品数量
    @GetMapping("selectList")
    public R flashPromotionSessionList(Long flashPromotionId){
        List<FlashPromotionSessionVo> list = flashSessionService.flashPromotionSessionVoList(flashPromotionId);
        return R.success(list);
    }

    //修改启用状态
    @PostMapping("update/status/{id}")
    public R updateFlashPromotionSessionStatus(Integer status,@PathVariable Long id){
        flashSessionService.updateFlashPromotionSessionStatus(id,status);
        return R.success();
    }

    //修改场次
    @PostMapping("update/{id}")
    public R updateFlashPromotionSession(@RequestBody FlashPromotionSession flashPromotionSession,@PathVariable Long id){
        flashSessionService.updateFlashPromotionSession(id,flashPromotionSession);
        return R.success();
    }

    //获取活动详情
    @GetMapping("{id}")
    public R getFlashPromotionSession(@PathVariable Long id){
        FlashPromotionSession flashPromotionSession = flashSessionService.getFlashPromotionSession(id);
        return R.success(flashPromotionSession);
    }
}
